package com.fansl.allround.study.Interview;

import java.util.HashMap;
import java.util.Hashtable;

/**
 * @author fansl
 * @Description: TODO
 * @date 2019/10/14 11:16
 */
public class MapTests{
    public static void hashMapTest(){
        HashMap<String,String> hashMap = new HashMap<>(1);
        hashMap.put(null,null);
        System.out.println(hashMap.get(null));
    }

    public MapTests() {
        super();
    }

    public static void hashtableTest(){
        Hashtable<String,String> hashtable = new Hashtable<>();
        hashtable.put(null,"hashtableTest");
        System.out.println(hashtable.get(null));
    }
    public static void main(String[] args) {
//        hashMapTest();
//        hashtableTest();
        HashMap hashMap = new HashMap<Integer,Object>(1,2);
        hashMap.put(1,1);
        hashMap.put(5,5);
        hashMap.put(9,9);
        hashMap.remove(1);
        for (int i=0;i<16;i++){
            System.out.println("i="+i+",size="+tableSizeFor(i));
        }
    }

    public static int tableSizeFor(int cap){
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return (n < 0) ? 1 : (n >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : n + 1;
    }
}
